package com.lvyq.myplayer.ui.fragment.music

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.google.android.material.textview.MaterialTextView
import com.lvyq.myplayer.R
import com.lvyq.myplayer.parcelable.SongInfoData

/**
 * 文件描述：MainMusicPagerFragment
 * 作者：lvyq
 * 创建时间：2025-07-29
 * 修改时间：2025-07-29
 */
class MainMusicPagerFragment(var data: SongInfoData): Fragment() {
    private lateinit var title: MaterialTextView
    private lateinit var singer: TextView

    private lateinit var mainMusicLayout: LinearLayout
    // 新增接口定义
    interface OnMainMusicClickListener {
        fun onMainMusicClick(position: Int,songInfoData: SongInfoData)
    }

    private var onItemClickListener: OnMainMusicClickListener? = null


    fun setOnItemClickListener(listener: OnMainMusicClickListener) {
        this.onItemClickListener = listener
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return  initView()
    }
    private fun initView(): View? {
        var view  = View.inflate(context, R.layout.item_fragment_main_play,null)
        title=view.findViewById(R.id.main_music_title)
        singer=view.findViewById(R.id.main_music_singer)
        mainMusicLayout=view.findViewById(R.id.main_music)

        title.text=data.title
        singer.text=data.singer
        // 添加点击监听
        mainMusicLayout.setOnClickListener {
            onItemClickListener?.onMainMusicClick(data?.position?:0,data)
        }
        return view
    }





}